package top.withwings.bonus.bonus.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.withwings.bonus.bonus.pojo.bonus.rule.BonusRule;
import top.withwings.bonus.bonus.service.RuleAttachmentService;
import top.withwings.bonus.bonus.service.RuleService;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("rule")
public class RuleController {

    @Autowired private RuleService ruleService;
    @Autowired private RuleAttachmentService ruleAttachmentService;

    @RequestMapping("all")
    public List<BonusRule> getRules(){
        return ruleService.listRules();
    }


    @RequestMapping("detach")
    public void detach(int[] goodIds,String type){
        ruleAttachmentService.detachRule(type,goodIds);
    }

    @RequestMapping("attach")
    public void detach(int[] goodIds,String type,int ruleId){
        ruleAttachmentService.attachRule(ruleId,goodIds);
    }

}
